<template>
  <div>
    <van-nav-bar
      title="地址列表"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-address-edit
      :area-list="areaList"
      :columns-num="2"
      show-postal
      show-set-default
      show-search-result
      :columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @delete="onDelete"
    />
  </div>
</template>

<script>
import Vue from "vue";
import { areaList } from "@vant/area-data";
import { AddressEdit, Area, Toast } from "vant";

Vue.use(Area);
import { doList, doDefaultAddress, doAdd } from "../api/address";

Vue.use(AddressEdit);
Vue.use(Toast);
export default {
  data() {
    return {
      areaList,
    };
  },
  methods: {
    onClickLeft() {
      this.$router.back();
    },
    onSave(val) {
      // Toast('save');
      console.log(val);
      doAdd({
        userid: localStorage.getItem("userid"),
        name: val.name,
        tel: val.tel,
        province: val.province,
        city: val.city,
        county: val.county,
        addressDetail: val.addressDetail,
        isDefault: val.isDefault,
      }).then((res) => {
        console.log(res);
        this.$router.back()
      });
    },
    onDelete() {
      Toast("delete");
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: "黄龙万科中心",
            address: "杭州市西湖区",
          },
        ];
      } else {
        this.searchResult = [];
      }
    },
  },
  created() {
    //地址列表
    let userid = localStorage.getItem("userid");
    doList({ userid:  localStorage.getItem("userid") }).then((res) => {
      console.log(userid);
      console.log(res);
    });
    doDefaultAddress({ userid:  localStorage.getItem("userid") }).then((res) => {
      console.log(userid);
      console.log(res);
    });
  },
};
</script>

<style scoped>
</style>